/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#ifndef INCLUDE_SHADER_STD
#define INCLUDE_SHADER_STD

#include "shader_ray.h"



#ifdef __cplusplus

// GLSL Type
using uint = unsigned int;
using uint64_t = uint64;
#define inout

#else

#include "shader_built_in_functions.h"

vec3 f_quatRot(in vec3 pos, in vec4 q) {
	vec3 newPos;
	newPos = pos * (2.0f * q.w * q.w - 1.0f) - cross(q.xyz, pos) * q.w * 2.0f + q.xyz * dot(q.xyz, pos) * 2.0f;
	return newPos;
}



// Randomly sampling around +Z
vec3 samplingHemisphere(inout uint seed, in vec3 x, in vec3 y, in vec3 z) {
	float r1 = f_rnd(seed);
	float r2 = f_rnd(seed);
	float sq = sqrt(1.0 - r2);

	vec3 direction = vec3(cos(2 * M_PI * r1) * sq, sin(2 * M_PI * r1) * sq, sqrt(r2));
	direction = direction.x * x + direction.y * y + direction.z * z;

	return direction;
}

// Return the tangent and binormal from the incoming normal
void createCoordinateSystem(in vec3 N, out vec3 Nt, out vec3 Nb) {
	if (abs(N.x) > abs(N.y))
		Nt = vec3(N.z, 0, -N.x) / sqrt(N.x * N.x + N.z * N.z);
	else
		Nt = vec3(0, -N.z, N.y) / sqrt(N.y * N.y + N.z * N.z);
	Nb = cross(N, Nt);
}


#endif



#define DEF_ObMeshBindID		3
#define DEF_MaterialsBindID		4

#define DEF_RenderFrameBindID	6
#define DEF_ParallelLightBindID	7
#define DEF_TexturesBindID		10





//������������
#define DEF_RayType             0
//������������
#define DEF_LigthRayType        1
//����ⷵ��
#define DEF_LigthReturnRayType  2
//����ⷵ��
//#define DEF_LigthReturnRayType  2





struct S_LigthParallel {
	vec3 m_dir;
	vec3 m_color;
	float m_intensity;	//ǿ��
	float m_falloff;
	float m_diffusivity;
	uint m_mask;
	uint m_enable;
};

struct S_LigthPoint {
	vec3 m_pos;
	vec3 m_color;
	float m_intensity;
	float m_falloff;
	uint m_mask;
	uint m_enable;
};

struct S_LigthArea {
	vec3 m_dir;
	vec3 m_color;
	float m_intensity;
	float m_falloff;
	//
	float m_diffusivity;
	uint m_mask;
	uint m_enable;
};

struct S_LigthSpot {
	vec3 m_dir;
	vec3 m_pos;
	vec3 m_color;
	float m_intensity;
	float m_falloff;
	//
	float m_diffusivity;
	uint m_mask;
	uint m_enable;
};










#endif



